//---------------------------------------------------------------------------
#include <vcl\vcl.h>
#pragma hdrstop

#include "CTEdit.h"
#include "eic.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
//TTreeEditor *TreeEditor;
//---------------------------------------------------------------------------
__fastcall TTreeEditor::TTreeEditor(TComponent* Owner)
    : TForm(Owner)
{
  m_DisplayInfos = false;
  m_pWindowView  = NULL;
  m_PropEditor   = NULL;
  m_OldTag       = -1;
  m_NewTag       = -1;

  Caption        = EICFormat("Editeur d'écrans version %d.%02d", (VERSION >> 8), (VERSION & 0x00FF));
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::InitCTreeEditor(CTree *pwview, TPropertyEditor *PropEdit)
{
  TTVChangedEvent evOldOnChange = NULL;

  m_pWindowView = pwview;
  m_PropEditor  = PropEdit;

  CNodeInfos *nodeinfos;
  TTreeNode  *node, *newnode;

  evOldOnChange = ScrTree->OnChange;
                  ScrTree->OnChange = NULL;
  ScrTree->Items->Clear();  // Efface l'arbre
  ScrTree->OnChange = evOldOnChange;

  // Génère l'arbre avec les extras-données contenu dans la DFM
  for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
    nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
    if (nodeinfos->TagParent != -1) {
      // Recherche le node parent dans l'arbre
      for(int j=0; j<ScrTree->Items->Count; j++) {
        node = ScrTree->Items->Item[j];
        if (TAG_NODE(node)==nodeinfos->TagParent) break;
      }
      newnode = ScrTree->Items->AddChild(node, nodeinfos->Text);
    } else newnode = ScrTree->Items->Add(NULL, nodeinfos->Text);
    // Ajoute les informations au node du TreeView
    TAG_NODE(newnode)      = nodeinfos->Tag;
    //TAG_NODE_AF( newnode, nodeinfos->Tag);
    newnode->ImageIndex    = nodeinfos->WindowStyle;
    newnode->SelectedIndex = nodeinfos->WindowStyle;
  }

  edPath    ->Text      = m_pWindowView->m_szPathHeader;
  rbSize    ->ItemIndex = m_pWindowView->m_nSizeAssist;
  cbRedim   ->Checked   = m_pWindowView->m_bResizeable;
  ScrVersion->Caption   = EICFormat("%d.%02d", (int)(m_pWindowView->m_nVersion >> 8) & 0x00ff, (int)m_pWindowView->m_nVersion & 0x00ff);
  if (m_pWindowView->m_nVersion != VERSION) ScrVersion->Font->Color = clRed;

  pwview->m_bEditCTree = true;

  if( pwview->Images) {
    cbIcons->Clear();
    cbIcons->Items->Add( EmptyStr);
    for( int i=0; i<pwview->Images->Count/2; i++) cbIcons->Items->Add( i);
  }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::BtnAjouterElementtClick(TObject *Sender)
{
  TNodeInfos  infos;
  TTreeNode  *Node;

  m_pWindowView->InitStandardInfos(&infos);
  if (ScrTree->Selected==NULL) m_pWindowView->AddMenu(-1, infos);
  else m_pWindowView->AddMenu(TAG_NODE(ScrTree->Selected), infos);

  Node = ScrTree->Items->Add(ScrTree->Selected, "");
  TAG_NODE(Node)      = infos.Tag;
  //TAG_NODE_AF( Node, infos.Tag);
  Node->ImageIndex    = infos.WindowStyle;
  Node->SelectedIndex = infos.WindowStyle;
  ScrTree->Selected   = Node;

  ScrName->SetFocus();

  OrganizeDatas();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::BtnAjouterSousElementClick(TObject *Sender)
{
  TNodeInfos  infos;
  TTreeNode  *Node;

  if (!ScrTree->Selected) return;

  // Ajoute un écran fils à un écran déjà existant
  m_pWindowView->InitStandardInfos(&infos);
  m_pWindowView->AddChildMenu(TAG_NODE(ScrTree->Selected), infos);

  Node = ScrTree->Items->AddChild(ScrTree->Selected, "");
  TAG_NODE(Node)      = infos.Tag;
  //TAG_NODE_AF( Node, infos.Tag);
  Node->ImageIndex    = infos.WindowStyle;
  Node->SelectedIndex = infos.WindowStyle;
  ScrTree->Selected   = Node;

  ScrName->SetFocus();

  OrganizeDatas();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrNameChange(TObject *Sender)
{
  ScrTree->Selected->Text = ScrName->Text;
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Text = ScrName->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::BtnSupprimerClick(TObject *Sender)
{
  CNodeInfos *nodeinfos;

  if (!ScrTree->Selected) return;

  // Si le node possède des enfants, on refuse de le supprimer
  // et on en avertit l'utilisateur
  if (!ScrTree->Selected->HasChildren) {
    for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
      nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
      if (nodeinfos->Tag == TAG_NODE(ScrTree->Selected)) {
         m_pWindowView->m_NodesInfos->Delete(i);
         break;
      }
    }
    ScrTree->Items->Delete(ScrTree->Selected);

    OrganizeDatas();
  } else EICErreur("Suppression impossible du noeud sélectionné !\nLe noeud possède des enfants.");
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::DisplayInformations()
{
  // Si on aucun node de sélectionné, on quitte la fonction
  if (!ScrTree->Selected) return;

  // Positionne un flag pour éviter à la fonction ScrModeBit7Click
  // de faire son traitement car dès que l'on modifie un check
  // l'évènement OnClick est appelé
  m_DisplayInfos           = true;

  // Affiche les informations du node en cours
  CNodeInfos *nodeinfos    =  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected));
  ScrName      ->Text      =  nodeinfos->Text;
  ScrDefineName->Text      =  nodeinfos->DefineName;
  ScrTag       ->Caption   =  IntToHex(nodeinfos->Tag      , 8);
  ScrTagParent ->Caption   =  IntToHex(nodeinfos->TagParent, 8);
  ScrClassName ->Text      =  nodeinfos->ClassName.SubString(2, nodeinfos->ClassName.Length()-1);
  ScrVisible   ->Checked   =  nodeinfos->Visible;
  ScrEnabled   ->Checked   =  nodeinfos->Enabled;
  ScrCreation  ->Checked   =  nodeinfos->MenuCreate;
  ScrTagMenu   ->Position  =  (short)nodeinfos->TagMenu;
  ScrFieldName ->Text      =  nodeinfos->FieldName;
  ScrBarElmSuiv->Checked   =  nodeinfos->DisplayBar;
  ScrKeyField  ->Text      =  nodeinfos->KeyField;
  ScrListField ->Text      =  nodeinfos->ListField;
  ScrContList  ->Checked   =  nodeinfos->HaveList;
  ScrModeBit0  ->Checked   = (nodeinfos->Mode & 0x0001);
  ScrModeBit1  ->Checked   = (nodeinfos->Mode & 0x0002);
  ScrModeBit2  ->Checked   = (nodeinfos->Mode & 0x0004);
  ScrModeBit3  ->Checked   = (nodeinfos->Mode & 0x0008);
  ScrModeBit4  ->Checked   = (nodeinfos->Mode & 0x0010);
  ScrModeBit5  ->Checked   = (nodeinfos->Mode & 0x0020);
  ScrModeBit6  ->Checked   = (nodeinfos->Mode & 0x0040);
  ScrModeBit7  ->Checked   = (nodeinfos->Mode & 0x0080);
  ScrWinStyle  ->ItemIndex =  nodeinfos->WindowStyle;
  ScrLettre    ->Position  =  nodeinfos->Level;
  cbIcons      ->ItemIndex =  nodeinfos->Icon + 1;

  // Grise les parties qui n'ont pas besoin d'être saisie
  // ou dont l'accès est interdit
  switch (nodeinfos->WindowStyle) {
    case SCR_CURELMT  : Enable_SCR_CURELMT();  break;
    case SCR_MENU     : Enable_SCR_MENU();     break;
    case SCR_SAISIE_M : Enable_SCR_MENU();     break;
    case SCR_AFFICH_M : Enable_SCR_MENU();     break;
    case SCR_EDITIO_M : Enable_SCR_MENU();     break;
    case SCR_COURRI_M : Enable_SCR_MENU();     break;
    case SCR_LISTE    : Enable_SCR_LISTE();    break;
    case SCR_SAISIE_L : Enable_SCR_SAISIE_L(); break;
    case SCR_AFFICH_L : Enable_SCR_AFFICH_L(); break;
    case SCR_EDITIO_L : Enable_SCR_AFFICH_L(); break;
    case SCR_COURRI_L : Enable_SCR_AFFICH_L(); break;
  }
  m_DisplayInfos = false;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrVisibleClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Visible = ScrVisible->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrEnabledClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Enabled = ScrEnabled->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrWinStyleClick(TObject *Sender)
{
  TTreeNode *Node        = ScrTree->Selected;
  CNodeInfos *nodeinfos  = m_pWindowView->FindNodeEdit(TAG_NODE(Node));

  if (m_DisplayInfos) return;

  nodeinfos->WindowStyle = ScrWinStyle->ItemIndex;
  // Passe le node courant à NULL puis à sa valeur initiale
  // ce qui a pour effet de modifier le bitmap dans le TreeView
  ScrTree->Selected      = NULL;
  Node->ImageIndex       = nodeinfos->WindowStyle;
  Node->SelectedIndex    = nodeinfos->WindowStyle;
  ScrTree->Selected      = Node;
  // Pour mettre à jour les zones enabled
  DisplayInformations();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrDefineNameChange(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->DefineName = ScrDefineName->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrTagMenuClick(TObject *Sender,
      TUDBtnType Button)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->TagMenu = ScrTagMenu->Position;
}
//---------------------------------------------------------------------------
int __fastcall TTreeEditor::FindIndexTag(int Tag)
{
  CNodeInfos *nodeinfos;

  // Recherche l'index dans la liste des extra-données qui
  // contient un tag donné
  for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
    nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
    if (nodeinfos->Tag == Tag) return (i);
  }
  return (-1);
}
//---------------------------------------------------------------------------
/*
void __fastcall TTreeEditor::ScrMoveUpClick(TObject *Sender)
{
  TTreeNode  *Node;
  // Vérifie les conditions pour pouvoir permuter
  if (!ScrTree->Selected || !ScrTree->Selected->Parent) return;
  if ((Node=ScrTree->Selected->Parent->GetPrevChild(ScrTree->Selected))==NULL) return;
  ScrTree->Selected->MoveTo(Node, naInsert);
  OrganizeDatas();
}
*/
void __fastcall TTreeEditor::ScrMoveUpClick(TObject *Sender)
{
  TTreeNode  *Node = NULL;
  // Vérifie les conditions pour pouvoir permuter
  if ( !ScrTree->Selected) return;
  // Le node possède un node parent
  if ( ScrTree->Selected->Parent) {
    if ((Node=ScrTree->Selected->Parent->GetPrevChild(ScrTree->Selected))==NULL) return;
    ScrTree->Selected->MoveTo(Node, naInsert);
  } else {
  // Le node ne possède pas de node parent
    for( int i=0; i<ScrTree->Items->Count; i++) {
      if ( ScrTree->Items->Item[i]==ScrTree->Selected) break;
      if ( ScrTree->Items->Item[i]->Level==0) Node = ScrTree->Items->Item[i];
    }
    if ( Node) ScrTree->Selected->MoveTo(Node, naInsert);
  }

  OrganizeDatas();
}
//---------------------------------------------------------------------------
/*
void __fastcall TTreeEditor::ScrMoveDownClick(TObject *Sender)
{
  TTreeNode  *Node;
  // Vérifie les conditions pour pouvoir permuter
  if (!ScrTree->Selected || !ScrTree->Selected->Parent) return;
  if ((Node=ScrTree->Selected->Parent->GetNextChild(ScrTree->Selected))==NULL) return;
  Node->MoveTo(ScrTree->Selected, naInsert);
  OrganizeDatas();
}
*/
void __fastcall TTreeEditor::ScrMoveDownClick(TObject *Sender)
{
  TTreeNode  *Node     = NULL;
  bool        bFindSel = false;
  // Vérifie les conditions pour pouvoir permuter
  if ( !ScrTree->Selected) return;
  // Le node possède un node parent
  if ( ScrTree->Selected->Parent) {
    if ((Node=ScrTree->Selected->Parent->GetNextChild(ScrTree->Selected))==NULL) return;
    Node->MoveTo(ScrTree->Selected, naInsert);
  } else {
  // Le node ne possède pas de node parent
    for( int i=0; i<ScrTree->Items->Count; i++) {
      if (( ScrTree->Items->Item[i]->Level==0) && bFindSel) { Node = ScrTree->Items->Item[i]; break; }
      if  ( ScrTree->Items->Item[i]==ScrTree->Selected) bFindSel = true;
    }
    if ( Node) Node->MoveTo( ScrTree->Selected, naInsert);
  }
  OrganizeDatas();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrChoiceClick(TObject *Sender)
{
  try {
    int          index;
    CNodeInfos  *nodeinfos;
    TTreeChoice *FenChoice = new TTreeChoice(this);

    // Affiche la liste de tous les écrans existants
    FenChoice->ListScreens->Clear();
    for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
      nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
      if (!IS_CURRENTELEM(nodeinfos->WindowStyle))
        FenChoice->ListScreens->Items->Add( nodeinfos->ClassName+" | "+nodeinfos->Text );
    }

    // Remplace l'écran par un écran déjà existant
    // sélectionné dans la liste
    if (FenChoice->ShowModal()==mrOk) {
      if ((index=FenChoice->ListScreens->ItemIndex) != -1) {
        AnsiString nScr = FenChoice->ListScreens->Items->Strings[index];
        //m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->ClassName = nScr.SubString(1, nScr.Pos(" | ")-1);
        ScrClassName->Text = nScr.SubString(1, nScr.Pos(" | ")-1);
      }
    }

    delete FenChoice;
  } catch (...) {
  }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrCreationClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->MenuCreate = ScrCreation->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ReplaceTag(int newTag, int oldTag)
{
  CNodeInfos *nodeinfos;
  // Remplace un numéro de tag par un autre
  for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
    nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
    if (nodeinfos->Tag      ==oldTag) nodeinfos->Tag      =newTag;
    if (nodeinfos->TagParent==oldTag) nodeinfos->TagParent=newTag;
  }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::RegenerateTags()
{
  CNodeInfos *nodeinfos;
  int         maxvalue = 0x7fffffff;
  // Remplace tous les Tags par des numéros différents
  for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
    nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
    if (m_OldTag==nodeinfos->Tag) m_OldTag=maxvalue;
    ReplaceTag(maxvalue--, nodeinfos->Tag);
  }
  // Remet des numéros de Tag de 1 à n
  for(int i=0; i<m_pWindowView->m_NodesInfos->Count; i++) {
    nodeinfos = (CNodeInfos *)m_pWindowView->m_NodesInfos->Items[i];
    if (m_OldTag==nodeinfos->Tag) m_NewTag=i+1;
    ReplaceTag(i+1, nodeinfos->Tag);
  }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::FormClose(TObject *Sender,
      TCloseAction &Action)
{
  m_pWindowView->m_szPathHeader = edPath ->Text;
  m_pWindowView->m_nSizeAssist  = rbSize ->ItemIndex;
  m_pWindowView->m_bResizeable  = cbRedim->Checked;
  RegenerateTags();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrKeyFieldChange(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->KeyField = ScrKeyField->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrListFieldChange(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->ListField = ScrListField->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrTreeChange(TObject *Sender,
      TTreeNode *Node)
{
  DisplayInformations();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrClassNameChange(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->ClassName = "T"+ScrClassName->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrModeBit7Click(TObject *Sender)
{
  short value = 0;

  // Si on est en cours d'affichage des infos, on ne fait rien
  if (m_DisplayInfos) return;

  // Calcule le mode en fonction des différents checks
  if (ScrModeBit0 ->Checked) value |= 0x0001;
  if (ScrModeBit1 ->Checked) value |= 0x0002;
  if (ScrModeBit2 ->Checked) value |= 0x0004;
  if (ScrModeBit3 ->Checked) value |= 0x0008;
  if (ScrModeBit4 ->Checked) value |= 0x0010;
  if (ScrModeBit5 ->Checked) value |= 0x0020;
  if (ScrModeBit6 ->Checked) value |= 0x0040;
  if (ScrModeBit7 ->Checked) value |= 0x0080;
  if (ScrModeBit8 ->Checked) value |= 0x0100;
  if (ScrModeBit9 ->Checked) value |= 0x0200;
  if (ScrModeBit10->Checked) value |= 0x0400;
  if (ScrModeBit11->Checked) value |= 0x0800;
  if (ScrModeBit12->Checked) value |= 0x1000;
  if (ScrModeBit13->Checked) value |= 0x2000;
  if (ScrModeBit14->Checked) value |= 0x4000;
  if (ScrModeBit15->Checked) value |= 0x8000;
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Mode = value;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::OrganizeDatas()
{
  int i;
  // Déplace les extra-données afin qu'elles se suivent
  for(i=0; i<ScrTree->Items->Count; i++) {
    int tag_elmnt = TAG_NODE(ScrTree->Items->Item[i]);
    m_pWindowView->m_NodesInfos->Move(FindIndexTag(tag_elmnt), i);
  }
  m_OldTag = TAG_NODE(ScrTree->Selected);
  RegenerateTags();
  InitCTreeEditor(m_pWindowView, m_PropEditor);
  // Recherche l'élément précédemment sélectionné
  for(i=0; i<ScrTree->Items->Count; i++)
    if (TAG_NODE(ScrTree->Items->Item[i])==m_NewTag) { ScrTree->Selected=ScrTree->Items->Item[i]; break; }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrTreeDragOver(TObject *Sender,
      TObject *Source, int X, int Y, TDragState State, bool &Accept)
{
  Accept = (ScrTree->Selected != NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrTreeDragDrop(TObject *Sender,
      TObject *Source, int X, int Y)
{
  TTreeNode *NodeDestination = ScrTree->GetNodeAt(X, Y);
  TTreeNode *NodeSelected    = ScrTree->Selected;
  // Si Source=Destination, on arrête le traitement
  if (NodeDestination==NodeSelected) return;
  // Si laché n'a pas de destination, on ne fait rien
  if (!NodeDestination) return;
  // Vérifie que l'on déplace pas un père dans un de ses fils
  if (NodeDestination->HasAsParent(NodeSelected)) {
    EICErreur("Impossible de déplacer un père dans son fils.");
    return;
  }
  // Sinon, on déplace l'élément sélectionné
  m_pWindowView->FindNodeEdit((int)ScrTree->Selected->Data)->TagParent = m_pWindowView->FindNodeEdit((int)NodeDestination->Data)->Tag;
  ScrTree->Selected->MoveTo(NodeDestination, naAddChild);
  OrganizeDatas();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::BtnQuitterClick(TObject *Sender)
{
  Close();
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrBarElmSuivClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->DisplayBar = ScrBarElmSuiv->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrFieldNameChange(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->FieldName = ScrFieldName->Text;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Enable_SCR_CURELMT()
{
  ScrName      ->Enabled =  true; Label1 ->Enabled =  true;
  ScrDefineName->Enabled =  true; Label5 ->Enabled =  true;
  ScrClassName ->Enabled = false; Label4 ->Enabled = false;
  ScrChoice    ->Enabled = false;
  ScrVisible   ->Enabled = false;
  ScrEnabled   ->Enabled = false;
  ScrCreation  ->Enabled = false; Label8 ->Enabled = false;
  ScrTagMenu   ->Enabled = false; Label6 ->Enabled = false; Edit1->Enabled = false;
  ScrLettre    ->Enabled = false; Label13->Enabled = false; Edit2->Enabled = false;
  ScrFieldName ->Enabled = false; Label12->Enabled = false;
//  ScrKeyField  ->Enabled = false; Label9 ->Enabled = false;
//  ScrListField ->Enabled = false; Label10->Enabled = false;
  ScrBarElmSuiv->Enabled = false;
  ScrContList  ->Enabled = false;
  ScrModeBit0  ->Enabled = false;
  ScrModeBit1  ->Enabled = false;
  ScrModeBit2  ->Enabled = false;
  ScrModeBit3  ->Enabled = false;
  ScrModeBit4  ->Enabled = false;
  ScrModeBit5  ->Enabled = false;
  ScrModeBit6  ->Enabled = false;
  ScrModeBit7  ->Enabled = false; Label11->Enabled = false;
  ScrModeBit8  ->Enabled = false;
  ScrModeBit9  ->Enabled = false;
  ScrModeBit10 ->Enabled = false;
  ScrModeBit11 ->Enabled = false;
  ScrModeBit12 ->Enabled = false;
  ScrModeBit13 ->Enabled = false;
  ScrModeBit14 ->Enabled = false;
  ScrModeBit15 ->Enabled = false;
  ScrWinStyle  ->Enabled =  true;
  cbIcons      ->Enabled = false;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Enable_SCR_MENU()
{
  ScrName      ->Enabled =  true; Label1 ->Enabled =  true;
  ScrDefineName->Enabled =  true; Label5 ->Enabled =  true;
  ScrClassName ->Enabled =  true; Label4 ->Enabled =  true;
  ScrChoice    ->Enabled =  true;
  ScrVisible   ->Enabled =  true;
  ScrEnabled   ->Enabled =  true;
  ScrCreation  ->Enabled = false; Label8 ->Enabled = false;
  ScrTagMenu   ->Enabled =  true; Label6 ->Enabled =  true; Edit1->Enabled =  true;
  ScrLettre    ->Enabled =  true; Label13->Enabled =  true; Edit2->Enabled =  true;
  ScrFieldName ->Enabled = false; Label12->Enabled = false;
//  ScrKeyField  ->Enabled = false; Label9 ->Enabled = false;
//  ScrListField ->Enabled = false; Label10->Enabled = false;
  ScrBarElmSuiv->Enabled = false;
  ScrContList  ->Enabled = false;
  ScrModeBit0  ->Enabled =  true;
  ScrModeBit1  ->Enabled =  true;
  ScrModeBit2  ->Enabled =  true;
  ScrModeBit3  ->Enabled =  true;
  ScrModeBit4  ->Enabled =  true;
  ScrModeBit5  ->Enabled =  true;
  ScrModeBit6  ->Enabled =  true;
  ScrModeBit7  ->Enabled =  true; Label11->Enabled =  true;
  ScrModeBit8  ->Enabled =  true;
  ScrModeBit9  ->Enabled =  true;
  ScrModeBit10 ->Enabled =  true;
  ScrModeBit11 ->Enabled =  true;
  ScrModeBit12 ->Enabled =  true;
  ScrModeBit13 ->Enabled =  true;
  ScrModeBit14 ->Enabled =  true;
  ScrModeBit15 ->Enabled =  true;
  ScrWinStyle  ->Enabled =  true;
  cbIcons      ->Enabled = ( m_pWindowView->Images!=NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Enable_SCR_AFFICH_L()
{
  ScrName      ->Enabled =  true; Label1 ->Enabled =  true;
  ScrDefineName->Enabled =  true; Label5 ->Enabled =  true;
  ScrClassName ->Enabled =  true; Label4 ->Enabled =  true;
  ScrChoice    ->Enabled =  true;
  ScrVisible   ->Enabled =  true;
  ScrEnabled   ->Enabled =  true;
  ScrCreation  ->Enabled = false; Label8 ->Enabled = false;
  ScrTagMenu   ->Enabled =  true; Label6 ->Enabled =  true; Edit1->Enabled =  true;
  ScrLettre    ->Enabled =  true; Label13->Enabled =  true; Edit2->Enabled =  true;
  ScrFieldName ->Enabled = false; Label12->Enabled = false;
//  ScrKeyField  ->Enabled = false; Label9 ->Enabled = false;
//  ScrListField ->Enabled = false; Label10->Enabled = false;
  ScrBarElmSuiv->Enabled =  true;
  ScrContList  ->Enabled = false;
  ScrModeBit0  ->Enabled =  true;
  ScrModeBit1  ->Enabled =  true;
  ScrModeBit2  ->Enabled =  true;
  ScrModeBit3  ->Enabled =  true;
  ScrModeBit4  ->Enabled =  true;
  ScrModeBit5  ->Enabled =  true;
  ScrModeBit6  ->Enabled =  true;
  ScrModeBit7  ->Enabled =  true; Label11->Enabled =  true;
  ScrWinStyle  ->Enabled =  true;
  cbIcons      ->Enabled = ( m_pWindowView->Images!=NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Enable_SCR_LISTE()
{
  ScrName      ->Enabled =  true; Label1 ->Enabled =  true;
  ScrDefineName->Enabled =  true; Label5 ->Enabled =  true;
  ScrClassName ->Enabled =  true; Label4 ->Enabled =  true;
  ScrChoice    ->Enabled =  true;
  ScrVisible   ->Enabled =  true;
  ScrEnabled   ->Enabled =  true;
  ScrCreation  ->Enabled = false; Label8 ->Enabled = false;
  ScrTagMenu   ->Enabled =  true; Label6 ->Enabled =  true; Edit1->Enabled =  true;
  ScrLettre    ->Enabled =  true; Label13->Enabled =  true; Edit2->Enabled =  true;
  ScrFieldName ->Enabled =  true; Label12->Enabled =  true;
//  ScrKeyField  ->Enabled =  true; Label9 ->Enabled =  true;
//  ScrListField ->Enabled =  true; Label10->Enabled =  true;
  ScrBarElmSuiv->Enabled =  true;
  ScrContList  ->Enabled =  true;
  ScrModeBit0  ->Enabled =  true;
  ScrModeBit1  ->Enabled =  true;
  ScrModeBit2  ->Enabled =  true;
  ScrModeBit3  ->Enabled =  true;
  ScrModeBit4  ->Enabled =  true;
  ScrModeBit5  ->Enabled =  true;
  ScrModeBit6  ->Enabled =  true;
  ScrModeBit7  ->Enabled =  true; Label11->Enabled =  true;
  ScrWinStyle  ->Enabled =  true;
  cbIcons      ->Enabled = ( m_pWindowView->Images!=NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Enable_SCR_SAISIE_L()
{
  ScrName      ->Enabled =  true; Label1 ->Enabled =  true;
  ScrDefineName->Enabled =  true; Label5 ->Enabled =  true;
  ScrClassName ->Enabled =  true; Label4 ->Enabled =  true;
  ScrChoice    ->Enabled =  true;
  ScrVisible   ->Enabled =  true;
  ScrEnabled   ->Enabled =  true;
  ScrCreation  ->Enabled =  true; Label8 ->Enabled =  true;
  ScrTagMenu   ->Enabled =  true; Label6 ->Enabled =  true; Edit1->Enabled =  true;
  ScrLettre    ->Enabled =  true; Label13->Enabled =  true; Edit2->Enabled =  true;
  ScrFieldName ->Enabled = false; Label12->Enabled = false;
//  ScrKeyField  ->Enabled = false; Label9 ->Enabled = false;
//  ScrListField ->Enabled = false; Label10->Enabled = false;
  ScrBarElmSuiv->Enabled =  true;
  ScrContList  ->Enabled = false;
  ScrModeBit0  ->Enabled =  true;
  ScrModeBit1  ->Enabled =  true;
  ScrModeBit2  ->Enabled =  true;
  ScrModeBit3  ->Enabled =  true;
  ScrModeBit4  ->Enabled =  true;
  ScrModeBit5  ->Enabled =  true;
  ScrModeBit6  ->Enabled =  true;
  ScrModeBit7  ->Enabled =  true; Label11->Enabled =  true;
  ScrWinStyle  ->Enabled =  true;
  cbIcons      ->Enabled = ( m_pWindowView->Images!=NULL);
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrTreeCollapsing(TObject *Sender,
      TTreeNode *Node, bool &AllowCollapse)
{
  //AllowCollapse = false;
  AllowCollapse = true;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrContListClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->HaveList = ScrContList->Checked;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::edPathDblClick(TObject *Sender)
{
  edPath->ReadOnly = false;
  edPath->Color    = clWindow;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::edPathExit(TObject *Sender)
{
  edPath->ReadOnly = true;
  edPath->Color    = clBtnFace;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::ScrLettreClick(TObject *Sender,
      TUDBtnType Button)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Level = ScrLettre->Position;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::Edit2Change(TObject *Sender)
{
  if (!ScrTree->Selected) return;
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Level = ScrLettre->Position;
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::cbIconsDrawItem(TWinControl *Control,
      int Index, TRect &Rect, TOwnerDrawState State)
{
  cbIcons->Canvas->FillRect( Rect);
  if( Index>0) {
    Graphics::TBitmap *bmp = new Graphics::TBitmap();
    m_pWindowView->Images->GetBitmap( 2*( Index-1), bmp); bmp->Transparent = true;
    cbIcons->Canvas->Draw( Rect.Left + 2, Rect.Top + 1, bmp);
    delete bmp;
  }
}
//---------------------------------------------------------------------------
void __fastcall TTreeEditor::cbIconsClick(TObject *Sender)
{
  m_pWindowView->FindNodeEdit(TAG_NODE(ScrTree->Selected))->Icon = cbIcons->ItemIndex - 1;
}
//---------------------------------------------------------------------------

